<template>
  <div class="mt-15">
    <el-table ref="multipleTable" v-loading="loading" tooltip-effect="darkTable" :height="height" :data="dealList" border :row-key="getRowKeys" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="40" align="center" prop="id" :reserve-selection="true" />
      <el-table-column :label="$t('项目名称')" align="center" prop="dealName" />
      <el-table-column :label="$t('项目负责人')" align="center" prop="personCharge.nickName" />
      <el-table-column :label="$t('首次划款时间')" align="center" prop="holderRatio" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.firstPayTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('投资金额') + $t('金额单位')" align="center" prop="investAmount" width="180">
        <template slot-scope="scope">
          <span>{{ moneyFormat(scope.row.payment, 'w') }}</span>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script>
import { findDealKeyInfo } from '@/api/base/deal/dealBase'
export default {
  name: 'MultipleDeal',
  props: {
    value: {
      type: Array,
      default() {
        return []
      }
    },
    height: {
      type: String,
      default: () => ''
    }
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 项目ID集合
      dealIds: [],
      // 总条数
      total: 0,
      // 查询参数
      queryParams: {
        companyId: this.bussId,
        changeId: undefined
      },
      // 项目列表
      dealList: []

    }
  },
  watch: {
    value(newVal) {
      this.dealIds = newVal
    },
    dealIds(newVal, oldVal) {
      if (newVal !== oldVal) {
        this.$emit('input', this.dealIds)
        this.$emit('change', this.dealIds)
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      this.loading = true
      findDealKeyInfo(this.queryParams).then(response => {
        this.dealList = response.rows
        var tempDealList = response.rows
        if (this.value) {
          for (var i = 0; i < tempDealList.length; i++) {
            if (this.value.indexOf(tempDealList[i].id) > -1) {
              this.$refs.multipleTable.toggleRowSelection(tempDealList[i], true)
            }
          }
        }
        this.loading = false
      })
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.dealIds = selection.map(item => item.id)
    },
    getRowKeys(row) {
      return row.id
    }
  }
}
</script>
